Trò chơi Tic-Tac-Toe, game đánh caro full source code
53.497 lượt xem;
- SupportLogger.cs
- UtilityScripts /
- Photon Unity Networking /
- Assets /
- project /
1 using System.Text;
2 using UnityEngine;
3 using System.Collections;
4
5 public class SupportLogger : MonoBehaviour
6 {
7 public bool LogTrafficStats = true;
8
9 public void Start()
10 {
11 GameObject go = GameObject.Find("PunSupportLogger");
12 if (go == null)
13 {
14 go = new GameObject("PunSupportLogger");
15 DontDestroyOnLoad(go);
16 SupportLogging sl = go.AddComponent<SupportLogging>();
17 sl.LogTrafficStats = this.LogTrafficStats;
18 }
19 }
20 }
21
22 public class SupportLogging : MonoBehaviour
23 {
24 public bool LogTrafficStats;
25
26 public void Start()
27 {
28 if (LogTrafficStats)
29 {
30 this.InvokeRepeating("LogStats", 10, 10);
31 }
32 }
33
34 public void OnApplicationQuit()
35 {
36 this.CancelInvoke();
37 }
38
39 public void LogStats()
40 {
41 if (this.LogTrafficStats)
42 {
43 Debug.Log("SupportLogger " + PhotonNetwork.NetworkStatisticsToString());
44 }
45 }
46
47 private void LogBasics()
48 {
49 StringBuilder sb = new StringBuilder();
50 sb.AppendFormat("SupportLogger Info: PUN {0}: ", PhotonNetwork.versionPUN);
51
52 sb.AppendFormat("AppID: {0}*** GameVersion: {1} ", PhotonNetwork.networkingPeer.mAppId.Substring(0, 8), PhotonNetwork.networkingPeer.mAppVersionPun);
53 sb.AppendFormat("Server: {0}. Region: {1} ", PhotonNetwork.ServerAddress, PhotonNetwork.networkingPeer.CloudRegion);
54 sb.AppendFormat("HostType: {0} ", PhotonNetwork.PhotonServerSettings.HostType);
55
56
57 Debug.Log(sb.ToString());
58 }
59
60
61 public void OnConnectedToPhoton()
62 {
63 Debug.Log("SupportLogger OnConnectedToPhoton().");
64 this.LogBasics();
65
66 if (LogTrafficStats)
67 {
68 PhotonNetwork.NetworkStatisticsEnabled = true;
69 }
70 }
71
72 public void OnFailedToConnectToPhoton(DisconnectCause cause)
73 {
74 Debug.Log("SupportLogger OnFailedToConnectToPhoton("+cause+").");
75 this.LogBasics();
76 }
77
78 public void OnJoinedLobby()
79 {
80 Debug.Log("SupportLogger OnJoinedLobby(" + PhotonNetwork.lobby + ").");
81 }
82
83 public void OnJoinedRoom()
84 {
85 Debug.Log("SupportLogger OnJoinedRoom(" + PhotonNetwork.room + "). " + PhotonNetwork.lobby + " GameServer:" + PhotonNetwork.ServerAddress);
86 }
87
88 public void OnCreatedRoom()
89 {
90 Debug.Log("SupportLogger OnCreatedRoom(" + PhotonNetwork.room + "). " + PhotonNetwork.lobby + " GameServer:" + PhotonNetwork.ServerAddress);
91 }
92
93 public void OnLeftRoom()
94 {
95 Debug.Log("SupportLogger OnLeftRoom().");
96 }
97 }
2 using UnityEngine;
3 using System.Collections;
4
5 public class SupportLogger : MonoBehaviour
6 {
7 public bool LogTrafficStats = true;
8
9 public void Start()
10 {
11 GameObject go = GameObject.Find("PunSupportLogger");
12 if (go == null)
13 {
14 go = new GameObject("PunSupportLogger");
15 DontDestroyOnLoad(go);
16 SupportLogging sl = go.AddComponent<SupportLogging>();
17 sl.LogTrafficStats = this.LogTrafficStats;
18 }
19 }
20 }
21
22 public class SupportLogging : MonoBehaviour
23 {
24 public bool LogTrafficStats;
25
26 public void Start()
27 {
28 if (LogTrafficStats)
29 {
30 this.InvokeRepeating("LogStats", 10, 10);
31 }
32 }
33
34 public void OnApplicationQuit()
35 {
36 this.CancelInvoke();
37 }
38
39 public void LogStats()
40 {
41 if (this.LogTrafficStats)
42 {
43 Debug.Log("SupportLogger " + PhotonNetwork.NetworkStatisticsToString());
44 }
45 }
46
47 private void LogBasics()
48 {
49 StringBuilder sb = new StringBuilder();
50 sb.AppendFormat("SupportLogger Info: PUN {0}: ", PhotonNetwork.versionPUN);
51
52 sb.AppendFormat("AppID: {0}*** GameVersion: {1} ", PhotonNetwork.networkingPeer.mAppId.Substring(0, 8), PhotonNetwork.networkingPeer.mAppVersionPun);
53 sb.AppendFormat("Server: {0}. Region: {1} ", PhotonNetwork.ServerAddress, PhotonNetwork.networkingPeer.CloudRegion);
54 sb.AppendFormat("HostType: {0} ", PhotonNetwork.PhotonServerSettings.HostType);
55
56
57 Debug.Log(sb.ToString());
58 }
59
60
61 public void OnConnectedToPhoton()
62 {
63 Debug.Log("SupportLogger OnConnectedToPhoton().");
64 this.LogBasics();
65
66 if (LogTrafficStats)
67 {
68 PhotonNetwork.NetworkStatisticsEnabled = true;
69 }
70 }
71
72 public void OnFailedToConnectToPhoton(DisconnectCause cause)
73 {
74 Debug.Log("SupportLogger OnFailedToConnectToPhoton("+cause+").");
75 this.LogBasics();
76 }
77
78 public void OnJoinedLobby()
79 {
80 Debug.Log("SupportLogger OnJoinedLobby(" + PhotonNetwork.lobby + ").");
81 }
82
83 public void OnJoinedRoom()
84 {
85 Debug.Log("SupportLogger OnJoinedRoom(" + PhotonNetwork.room + "). " + PhotonNetwork.lobby + " GameServer:" + PhotonNetwork.ServerAddress);
86 }
87
88 public void OnCreatedRoom()
89 {
90 Debug.Log("SupportLogger OnCreatedRoom(" + PhotonNetwork.room + "). " + PhotonNetwork.lobby + " GameServer:" + PhotonNetwork.ServerAddress);
91 }
92
93 public void OnLeftRoom()
94 {
95 Debug.Log("SupportLogger OnLeftRoom().");
96 }
97 }